import 'package:flutter/material.dart';
import 'to_do_list_page.dart'; // Ensure this file exists and contains the ToDoListPage widget.
import 'base_component.dart';
import 'user_page.dart'; // Ensure this file exists and contains the UserPage widget.
import 'camera_page.dart';

class HomePage extends StatefulWidget {
  const HomePage({super.key});

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  int _currentIndex = 0; // 当前选中索引

  // 对应页面列表（根据需求扩展）
  final List<Widget> _pages = [
    const HomeContent(), // 首页内容（需自定义）
    const UserPage(), // 用户页面（需自定义）
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(
            _currentIndex == 0 ? 'Home Page' : 'User Page'), // 动态标题, // 动态标题
      ),
      bottomNavigationBar: BottomNavigationBar(
        type: BottomNavigationBarType.fixed,
        currentIndex: _currentIndex, // 当前选中项
        onTap: (index) {
          setState(() {
            _currentIndex = index; // 更新选中状态
          });
        },
        items: const [
          BottomNavigationBarItem(
            icon: Icon(Icons.home),
            label: 'Home',
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.supervised_user_circle_outlined),
            label: 'User',
          ),
        ],
      ),
      body: _pages[_currentIndex], // 根据索引显示对应页面
    );
  }
}

// 示例：自定义 HomeContent 页面（需补充具体逻辑）
class HomeContent extends StatelessWidget {
  const HomeContent({super.key});

  @override
  Widget build(BuildContext context) {
    return Center(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          ElevatedButton(
            onPressed: () => Navigator.push(context,
                MaterialPageRoute(builder: (_) => const BaseComponent())),
            child: const Text('Go to BaseComponent'),
          ),
          ElevatedButton(
            onPressed: () => Navigator.push(context,
                MaterialPageRoute(builder: (_) => const ToDoListPage())),
            child: const Text('Go to ToDo List'),
          ),
          ElevatedButton(
            onPressed: () => Navigator.push(
                context, MaterialPageRoute(builder: (_) => const CameraPage())),
            child: const Text('Go to CameraPage'),
          ),
        ],
      ),
    );
  }
}
